# -*- coding: utf-8 -*-
"""
Swagger API 文档配置
"""

# Swagger 配置
SWAGGER_CONFIG = {
    "head_text": "<title>体育场馆预约系统 API 文档</title>",
    "title": "体育场馆预约系统",
    "description": "体育场馆预约系统后端API接口文档 - 支持微信小程序预约、活动管理、支付、签到等功能",
    "version": "1.0.0",
    "termsOfService": "",
    "hide_top_bar": False,
    "swagger_ui": True,
    "specs_route": "/apidocs/",
    "static_url_path": "/flasgger_static",
    "headers": [],
    "swagger_ui_config": {
        "defaultModelRendering": "model",
        "defaultModelsExpandDepth": 2,
        "docExpansion": "list",
        "showExtensions": True,
        "showCommonExtensions": True,
        "deepLinking": True,
        "displayRequestDuration": True,
        "supportedSubmitMethods": ["get", "post", "put", "delete", "patch"],
        "tryItOutEnabled": True,
        "defaultModelExpandDepth": 3,
        "defaultModelRendering": "model",
        "displayOperationId": False,
        "displayRequestDuration": True,
        "maxDisplayedTags": 20,
        "showExtensions": False,
        "showCommonExtensions": False,
        "useUnsafeMarkdown": False
    },
    "specs": [
        {
            "endpoint": "apispec",
            "route": "/apispec_1.json",
            "rule_filter": lambda rule: True,
            "model_filter": lambda tag: True,
        }
    ],
    "doc_dir": "./docs/"
}

# API 文档规范
SWAGGER_TEMPLATE = {
    "swagger": "2.0",
    "info": {
        "title": "体育场馆预约系统 API",
        "description": "为微信小程序提供场馆预约、活动管理、支付、签到等服务的后端API",
        "contact": {
            "name": "开发团队",
            "email": "developer@venue-booking.com",
        },
        "termsOfService": "http://venue-booking.com/terms",
        "version": "1.0.0"
    },
    "host": "127.0.0.1:8089",
    "basePath": "/api/v1",
    "schemes": ["http"],
    # 兼容Swagger UI的Token输入
    "securityDefinitions": {
        "Bearer": {
            "type": "apiKey",
            "name": "Authorization",
            "in": "header",
            "description": "JWT认证，格式：Bearer {token}。请先通过登录接口获取token，在此处填写完整格式：Bearer <token>。示例：Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
        }
    },
    "security": [
        {
            "Bearer": []
        }
    ],
    "definitions": {
        "ApiResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "状态码"
                },
                "message": {
                    "type": "string",
                    "description": "响应消息"
                },
                "data": {
                    "type": "object",
                    "description": "响应数据"
                }
            }
        },
        "ErrorResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "错误码"
                },
                "message": {
                    "type": "string",
                    "description": "错误消息"
                }
            }
        }
    },
    "tags": [
        {
            "name": "用户认证",
            "description": "用户登录、认证相关接口"
        },
        {
            "name": "场馆管理",
            "description": "场馆信息查询接口"
        },
        {
            "name": "支付系统",
            "description": "微信支付相关接口"
        },
        {
            "name": "Banner",
            "description": "用户端横幅广告接口"
        },
        {
            "name": "Banner管理",
            "description": "管理员横幅广告管理接口"
        },
        {
            "name": "活动管理",
            "description": "管理员活动管理、统计、参与者管理等后台接口"
        },
        {
            "name": "用户管理",
            "description": "管理员用户管理、关系管理等后台接口"
        },
        {
            "name": "管理员",
            "description": "管理员认证与系统管理接口"
        }
    ]
}

# 通用响应模型
COMMON_RESPONSES = {
    "200": {
        "description": "请求成功",
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/ApiResponse"
                }
            }
        }
    },
    "400": {
        "description": "请求参数错误",
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/ErrorResponse"
                }
            }
        }
    },
    "401": {
        "description": "未授权访问",
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/ErrorResponse"
                }
            }
        }
    },
    "404": {
        "description": "资源不存在",
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/ErrorResponse"
                }
            }
        }
    },
    "500": {
        "description": "服务器内部错误",
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/ErrorResponse"
                }
            }
        }
    }
} 